package concurrentsandbox;

public class SelectMaxProblem {
	private static final int SLOW_DOWN = 1000;
	private final boolean slowDown = true;
	private final int[] numbers;
	private final int start;
	private final int end;
	public final int size;

	public SelectMaxProblem(int[] numbers, int start, int end) {
		this.numbers = numbers;
		this.start = start;
		this.end = end;
		this.size = end - start;
	}

	public int solveSequentially() {
		int max = solveSequentiallySimple();
		if (slowDown) {
			for (int i = 0; i < SLOW_DOWN; i++) {
				max = solveSequentiallySimple();
			}
		}
		return max;
	}

	public int solveSequentiallySimple() {
		int max = Integer.MIN_VALUE;
		for (int i = start; i < end; i++) {
			int number = numbers[i];
			if (number > max) {
				max = number;
			}
		}
		return max;
	}

	public SelectMaxProblem subproblem(int subStart, int subEnd) {
		return new SelectMaxProblem(numbers, start + subStart, start + subEnd);
	}
}